package com.jxc.servlet.ServletContext;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ServletContext/Default")
public class ServletContextDefaultServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 实例化一个ServletContext对象
        ServletContext context = req.getServletContext();
        // 提取自定义的属性
        String title = (String)context.getAttribute("title");
        String footer = (String) context.getAttribute("footer");
        resp.setContentType("text/html;charset=utf-8");
        resp.getWriter().print("<h1>"+title+"</h1>");
        resp.getWriter().print("<h1>"+footer+"</h1>");
    }
}
